package com.robert.controller;

import com.robert.entity.BlogEntity;
import com.robert.mapper.UserMapper;
import com.robert.service.BlogService;
import com.robert.util.Pager;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *
 * </p>
 *
 * @author robert zhao
 * @since 2020/5/6
 */
@Controller
public class BlogController {

  @Autowired
  private BlogService blogService;



  @RequestMapping(value = {"index/{currentNum}", "index"})
  public String hello(Model model,
      @PathVariable(value = "currentNum", required = false) Integer currentNum) {

    if (currentNum == null || currentNum <= 0) {
      currentNum = 1;
    }
    Pager pager = new Pager();
    pager.setCurrentNum(currentNum);
    List<BlogEntity> blogList = blogService.getBlogList(pager);
    model.addAttribute("blogs", blogList);
    model.addAttribute("pager", pager);
    return "index";
  }

}
